Called once per fusion cycle to stream information required by the NXP Sensor Fusion Toolbox. Packet protocols are defined in the NXP Sensor Fusion for Kinetis Product Development Kit User Guide.
148 static uint32_t iTimeStamp = 0;
161 uint8_t AngularVelocityPacketOn,
164 int8_t AccelCalPacketOn;
165 static uint8_t iPacketNumber = 0;
170 #if (MAXPACKETRATEHZ < FUSION_HZ) 172 if (skip_packet)
return;
224 switch (quaternionPacketType)
232 scratch32 = (sfg->Accel.iGc[
CHX] * 8192) / sfg->Accel.iCountsPerg;
233 if (scratch32 > 32767) scratch32 = 32767;
234 if (scratch32 < -32768) scratch32 = -32768;
235 scratch16 = (int16_t) (scratch32);
238 scratch32 = (sfg->Accel.iGc[
CHY] * 8192) / sfg->Accel.iCountsPerg;
239 if (scratch32 > 32767) scratch32 = 32767;
240 if (scratch32 < -32768) scratch32 = -32768;
241 scratch16 = (int16_t) (scratch32);
244 scratch32 = (sfg->Accel.iGc[
CHZ] * 8192) / sfg->Accel.iCountsPerg;
245 if (scratch32 > 32767) scratch32 = 32767;
246 if (scratch32 < -32768) scratch32 = -32768;
247 scratch16 = (int16_t) (scratch32);
250 #endif // F_USING_ACCEL 265 switch (quaternionPacketType)
298 switch (quaternionPacketType)
306 scratch16 = (int16_t) ((sfg->Gyro.iYs[
CHX] * 20) / sfg->Gyro.iCountsPerDegPerSec);
308 scratch16 = (int16_t) ((sfg->Gyro.iYs[
CHY] * 20) / sfg->Gyro.iCountsPerDegPerSec);
310 scratch16 = (int16_t) ((sfg->Gyro.iYs[
CHZ] * 20) / sfg->Gyro.iCountsPerDegPerSec);
331 fq.
q1 = fq.
q2 = fq.
q3 = 0.0F;
333 iOmega[
CHX] = iOmega[
CHY] = iOmega[
CHZ] = 0;
334 iPhi = iThe = iRho = iDelta = 0;
349 switch (quaternionPacketType)
356 readCommon((
SV_ptr)&sfg->SV_3DOF_G_BASIC, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
365 readCommon((
SV_ptr)&sfg->SV_3DOF_B_BASIC, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
374 readCommon((
SV_ptr)&sfg->SV_3DOF_Y_BASIC, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
383 iDelta = (int16_t) (10.0F * sfg->SV_6DOF_GB_BASIC.fLPDelta);
384 readCommon((
SV_ptr)&sfg->SV_6DOF_GB_BASIC, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
393 readCommon((
SV_ptr)&sfg->SV_6DOF_GY_KALMAN, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
397 #if F_9DOF_GBY_KALMAN 402 iDelta = (int16_t) (10.0F * sfg->SV_9DOF_GBY_KALMAN.fDeltaPl);
403 readCommon((
SV_ptr)&sfg->SV_9DOF_GBY_KALMAN, &fq, &iPhi, &iThe, &iRho, iOmega, &isystick);
413 scratch16 = (int16_t) (fq.
q0 * 30000.0F);
415 scratch16 = (int16_t) (fq.
q1 * 30000.0F);
417 scratch16 = (int16_t) (fq.
q2 * 30000.0F);
419 scratch16 = (int16_t) (fq.
q3 * 30000.0F);
423 #if THISCOORDSYSTEM == ANDROID 426 #elif THISCOORDSYSTEM == WIN8 429 #endif // THISCOORDSYSTEM 435 tmpuint8_t = ((THIS_SHIELD & 0x07) << 5) | (THIS_BOARD & 0x1F);
473 if (AngularVelocityPacketOn)
552 scratch32 = (int32_t) (sfg->SV_1DOF_P_BASIC.fLPH * 1000.0F);
556 scratch16 = (int16_t) (sfg->SV_1DOF_P_BASIC.fLPT * 100.0F);
571 static int16_t MagneticPacketID = 0;
597 scratch16 = (int16_t) (sfg->
MagCal.
fB * 10.0F);
601 k = MagneticPacketID - 10;
610 if ((MagneticPacketID >= 10) && (sfg->
MagBuffer.
index[i][j] == -1))
613 scratch16 = -MagneticPacketID;
619 scratch16 = MagneticPacketID;
626 switch (MagneticPacketID)
644 scratch16 = (int16_t) (sfg->
MagCal.
fV[
CHX] * 10.0F);
646 scratch16 = (int16_t) (sfg->
MagCal.
fV[
CHY] * 10.0F);
648 scratch16 = (int16_t) (sfg->
MagCal.
fV[
CHZ] * 10.0F);
664 scratch16 = (int16_t) (sfg->
MagCal.
finvW[CHX][CHY] * 1000.0F);
666 scratch16 = (int16_t) (sfg->
MagCal.
finvW[CHX][CHZ] * 1000.0F);
668 scratch16 = (int16_t) (sfg->
MagCal.
finvW[CHY][CHZ] * 1000.0F);
695 if (MagneticPacketID >= (10 + MAGBUFFSIZEX *
MAGBUFFSIZEY))
696 MagneticPacketID = 0;
712 kalman = six_axis_kalman;
714 #if F_9DOF_GBY_KALMAN 716 kalman = kalman | nine_axis_kalman;
718 #if F_6DOF_GY_KALMAN || F_9DOF_GBY_KALMAN 721 if ((quaternionPacketType ==
Q6AG) || (quaternionPacketType ==
Q9))
737 for (i = CHX; i <=
CHZ; i++)
740 if (six_axis_kalman) scratch16 = (int16_t) (sfg->SV_6DOF_GY_KALMAN.fZErr[i] * 30000.0F);
742 #if F_9DOF_GBY_KALMAN 743 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fZErr[i] * 30000.0F);
751 for (i = CHX; i <=
CHZ; i++)
754 if (six_axis_kalman) scratch16 = (int16_t) (sfg->SV_6DOF_GY_KALMAN.fqgErrPl[i] * 30000.0F);
756 #if F_9DOF_GBY_KALMAN 757 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fqgErrPl[i] * 30000.0F);
765 for (i = CHX; i <=
CHZ; i++)
768 if (six_axis_kalman) scratch16 = 0;
770 #if F_9DOF_GBY_KALMAN 771 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fZErr[i + 3] * 30000.0F);
779 for (i = CHX; i <=
CHZ; i++)
782 if (six_axis_kalman) scratch16 = 0;
784 #if F_9DOF_GBY_KALMAN 785 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fqmErrPl[i] * 30000.0F);
793 for (i = CHX; i <=
CHZ; i++)
796 if (six_axis_kalman) scratch16 = (int16_t) (sfg->SV_6DOF_GY_KALMAN.fbPl[i] * 1000.0F);
798 #if F_9DOF_GBY_KALMAN 799 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fbPl[i] * 1000.0F);
806 #if F_9DOF_GBY_KALMAN 807 if (nine_axis_kalman) scratch16 = (int16_t) (sfg->SV_9DOF_GBY_KALMAN.fDeltaPl * 100.0F);
814 for (i = CHX; i <=
CHZ; i++)
819 if (six_axis_kalman) ftmp = sfg->SV_6DOF_GY_KALMAN.fAccGl[i] * 8192.0F;
821 #if F_9DOF_GBY_KALMAN 822 if (nine_axis_kalman) ftmp = sfg->SV_9DOF_GBY_KALMAN.fAccGl[i] * 8192.0F;
826 if (ftmp > 32767.0F) scratch16 = 32767;
827 else if (ftmp < -32768.0F) scratch16 = -32768;
828 else scratch16 = (int16_t) ftmp;
835 for (i = CHX; i <=
CHZ; i++)
839 #if F_9DOF_GBY_KALMAN 840 if (nine_axis_kalman) ftmp = sfg->SV_9DOF_GBY_KALMAN.fDisGl[i] * 100.0F;
844 if (ftmp > 32767.0F) scratch16 = 32767;
845 else if (ftmp < -32768.0F) scratch16 = -32768;
846 else scratch16 = (int16_t) ftmp;
862 if (AccelCalPacketOn != -1)
878 (uint8_t *) &(AccelCalPacketOn), 1);
881 if ((AccelCalPacketOn >= 0) &&
884 scratch16 = (int16_t) (sfg->AccelBuffer.fGsStored[AccelCalPacketOn][CHX] * 8192.0F);
886 scratch16 = (int16_t) (sfg->AccelBuffer.fGsStored[AccelCalPacketOn][CHY] * 8192.0F);
888 scratch16 = (int16_t) (sfg->AccelBuffer.fGsStored[AccelCalPacketOn][CHZ] * 8192.0F);
898 scratch16 = (int16_t) (sfg->AccelCal.fV[CHX] * 32768.0F);
900 scratch16 = (int16_t) (sfg->AccelCal.fV[CHY] * 32768.0F);
902 scratch16 = (int16_t) (sfg->AccelCal.fV[CHZ] * 32768.0F);
906 scratch16 = (int16_t) ((sfg->AccelCal.finvW[CHX][CHX] - 1.0F) * 10000.0F);
908 scratch16 = (int16_t) ((sfg->AccelCal.finvW[CHY][CHY] - 1.0F) * 10000.0F);
910 scratch16 = (int16_t) ((sfg->AccelCal.finvW[CHZ][CHZ] - 1.0F) * 10000.0F);
914 scratch16 = (int16_t) (sfg->AccelCal.finvW[CHX][CHY] * 10000.0F);
916 scratch16 = (int16_t) (sfg->AccelCal.finvW[CHX][CHZ] * 10000.0F);
918 scratch16 = (int16_t) (sfg->AccelCal.finvW[CHY][CHZ] * 10000.0F);
922 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHX][CHX] * 10000.0F);
924 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHY][CHY] * 10000.0F);
926 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHZ][CHZ] * 10000.0F);
930 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHX][CHY] * 10000.0F);
932 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHX][CHZ] * 10000.0F);
934 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHY][CHX] * 10000.0F);
936 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHY][CHZ] * 10000.0F);
938 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHZ][CHX] * 10000.0F);
940 scratch16 = (int16_t) (sfg->AccelCal.fR0[CHZ][CHY] * 10000.0F);
949 #endif // F_USING_ACCEL enum quaternion quaternion_type
the quaternion type to be transmitted
Quaternion derived from full 9-axis sensor fusion.
#define MAGBUFFSIZEX
x dimension in magnetometer buffer (12x24 equals 288 elements)
#define F_USING_GYRO
nominally 0x0004 if a gyro is to be used, 0x0000 otherwise
#define CHY
Used to access Y-channel entries in various data data structures.
void readCommon(SV_ptr data, Quaternion *fq, int16_t *iPhi, int16_t *iThe, int16_t *iRho, int16_t iOmega[], uint16_t *isystick)
uint32_t iFlags
a bit-field of sensors and algorithms used
volatile uint8_t AltPacketOn
flag to enable altitude packet
Quaternion derived from 3-axis mag only (auto compass algorithm)
MagCalibration MagCal
mag cal storage
volatile int8_t AccelCalPacketOn
variable used to coordinate accelerometer calibration
float q3
z vector component
int16_t iMagBufferCount
number of magnetometer readings
Quaternion derived from 3-axis gyro only (rotation)
int16_t iCountsPeruT
counts per uT
Quaternion derived from 3-axis accel + 3 axis mag (eCompass)
Quaternion derived from 3-axis accel + 3-axis gyro (gaming)
uint16_t throttle()
(OVERSAMPLE_RATIO * MAXPACKETRATEHZ) / SENSORFS
struct ControlSubsystem * pControlSubsystem
MagSensor Mag
magnetometer storage
quaternion structure definition
#define F_1DOF_P_BASIC
1DOF pressure (altitude) and temperature algorithm selector - 0x0100 to include, 0x0000 otherwise ...
#define F_9DOF_GBY_KALMAN
void sBufAppendItem(uint8_t *pDest, uint16_t *pIndex, uint8_t *pSource, uint16_t iBytesToCopy)
Utility function used to place data in output buffer about to be transmitted via UART.
float finvW[3][3]
current inverse soft iron matrix
#define THISBUILD
define build number sent in debug packet for display purposes only
float fV[3]
current hard iron offset x, y, z, (uT)
#define F_6DOF_GY_KALMAN
6DOF accel and gyro (Kalman) algorithm selector - 0x2000 to include, 0x0000 otherwise ...
#define F_3DOF_G_BASIC
3DOF accel tilt (accel) algorithm selector - 0x0200 to include, 0x0000 otherwise
uint8_t sUARTOutputBuffer[256]
main output buffer defined in control.c
volatile uint8_t DebugPacketOn
flag to enable debug packet
#define MAX_ACCEL_CAL_ORIENTATIONS
number of stored precision accelerometer measurements
int16_t iBc[3]
averaged calibrated measurement (counts)
#define CHX
Used to access X-channel entries in various data data structures.
float fFitErrorpc
current fit error %
MagBuffer MagBuffer
mag cal constellation points
writePort_t * write
low level function to write a char buffer to the serial stream
volatile uint8_t RPCPacketOn
flag to enable roll, pitch, compass packet
Quaternion derived from 3-axis accel (tilt)
#define F_3DOF_Y_BASIC
3DOF gyro integration algorithm selector - 0x0800 to include, 0x0000 otherwise
#define F_6DOF_GB_BASIC
6DOF accel and mag eCompass algorithm selector - 0x1000 to include, 0x0000 otherwise ...
#define FUSION_HZ
(int) actual rate of fusion algorithm execution and sensor FIFO reads
int32_t index[MAGBUFFSIZEX][MAGBUFFSIZEY]
array of time indices
void sBufAppendZeros(uint8_t *pDest, uint16_t *pIndex, uint16_t numZeros)
float fB
current geomagnetic field magnitude (uT)
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
#define MAGBUFFSIZEY
y dimension in magnetometer buffer (12x24 equals 288 elements)
float q2
y vector component
#define F_3DOF_B_BASIC
3DOF mag eCompass (vehicle/mag) algorithm selector - 0x0400 to include, 0x0000 otherwise ...
Excluding SV_1DOF_P_BASIC, Any of the SV_ fusion structures above could be cast to type SV_COMMON for...
float q1
x vector component
int16_t iBs[3][MAGBUFFSIZEX][MAGBUFFSIZEY]
uncalibrated magnetometer readings
volatile quaternion_type QuaternionPacketType
quaternion type transmitted over UART
volatile uint8_t AngularVelocityPacketOn
flag to enable angular velocity packet